<template>
	<view class="content">
		<!-- 客户端 ++++++++++++++++++-->
		<view v-if="kehu">
			<view style="height: 220rpx;"></view>
			<view class="line_title">
				可用额度（元）
			</view>
			<view class="big-number line_title" >
				{{keyong}}
			</view>
			<view class="line_title">
				利率为{{lilv}}%
			</view>
			<view style="height: 120rpx;"></view>
			<view class="clear ed_container">
				<view class="left" style="width: 40%;">
					<view class="munber" >
						{{total}}
					</view>
					<view class="munber-name" >
						总额度（元）
					</view>
				</view>
				<view class="right ed_right" >
					<view class="munber" >
						{{yiyong}}
					</view>
					<view class="munber-name" >
						已用额度（元）
					</view>
				</view>
			</view>
			<view style="height: 220rpx;"></view>
			<view>
				<button class="big_button button_shadow" @tap="goloan()" style="height: 100rpx;line-height: 100rpx;border-radius: 50rpx; ">
					去贷款
				</button>
			</view>
			<view class="menban" v-show="isalert">
				<view class="gray"></view>
					<view class="menban-content" style="top:calc(50% - 200rpx);left: 10%;right: 10%;border-radius:5px ;">
						<view class="line_title blue_title" style="position: relative;">
							友情提示
							<image src="../../static/img/close-icon.png" class="close-icon" @tap="isalertAction"></image>
						</view>
						<view  class="text" style="padding: 0px 60rpx;">
							您的资料没有完善，请先完善资料
						</view>
						<button class="big_button" style="margin: 30rpx auto;" @tap="gowanshan()">
							立即去完善
						</button>
					</view>
			</view>
			<view class="menban" v-show="isshenhe">
				<view class="gray"></view>
					<view class="menban-content" style="top:calc(50% - 200rpx);left: 10%;right: 10%;border-radius:5px ;">
						<view class="line_title blue_title" style="position: relative;">
							友情提示
							<image src="../../static/img/close-icon.png" class="close-icon" @tap="isalertAction"></image>
						</view>
						<view  class="text" style="padding: 0px 60rpx;">
							您的资料正在审核
						</view>
						<!-- <button class="big_button" style="margin: 30rpx auto;" @tap="gowanshan()">
							立即去完善
						</button> -->
					</view>
			</view>
		</view>
		<!-- 业务端 ++++++++++++++++++-->
		<view v-if="yewu">
			<view style="height: 60rpx;"></view>
			<view class="line_title">待办事项</view>
			<view class="mokuai" style="margin: 30rpx;padding: 20rpx;">
				<view class="info_title" style="position: relative;">
				    贷款审核<text class="count" v-if="countshow1">{{capital_num}}</text>
					<text class="info_more" @tap="daikuaninfo()" >查看更多</text>
				</view>
				<view class="border_bottom shenhe_list_container" v-for="(item,index) in capital" :key="index" @tap="godaikuaninfo" :data-id="item.id">
					<view class="clear shenhe-text" >
						<text class="left" >客户姓名 </text>
						<text class="right blue_text" style="font-weight: bold;">{{item.username}}</text>
					</view>	
					<view class="clear shenhe-text" >
						<text class="left">申请金额 </text>
						<text class="right blue_text" style="font-weight: bold;">{{item.capital}}</text>
					</view>
						<view class="clear shenhe-text" >
						<text class="left">申请时间 </text>
						<text class="right">{{item.addtime}}</text>
					</view>
				</view>
		        <image src="../../static/img/nodata.png" class="no-data" v-if="ishas1"  mode="widthFix"></image>
				
			</view>
			<view class="mokuai" style="margin: 30rpx;padding: 20rpx;" v-if="user.top!=3">
				<view class="info_title" style="position: relative;">
				    客户资料审核<text class="count" v-if="countshow2" style="position: absolute;left: 28%!important;top: 15rpx;">{{member_num}}</text>
					<text class="info_more" @tap="kehuinfo()" >查看更多</text>
				</view>
				<view class="border_bottom shenhe_list_container" v-for="(item,index) in memebr" :key="index" @tap="gocsutem" :data-id="item.id">
					<view class="clear shenhe-text" >
						<text class="left">客户姓名 </text>
						<text class="right blue_text" style="font-weight: bold;">{{item.nickname}}</text>
					</view>	
					
					<view class="clear shenhe-text" >
						<text class="left">申请时间 </text>
						<text class="right">{{item.addtime}}</text>
					</view>
					
				</view>
				<image src="../../static/img/nodata.png" class="no-data" v-if="ishas2"  mode="widthFix"></image>
				<!-- <view class="border_bottom shenhe_list_container">
					<view class="clear shenhe-text" >
						<text class="left">客户姓名 </text>
						<text class="right blue_text">刘月月</text>
					</view>	
					
					<view class="clear shenhe-text" >
						<text class="left">申请时间 </text>
						<text class="right">2020-12-12</text>
					</view>
				</view> -->
				
			</view>
			<view class="mokuai" style="margin: 30rpx;padding: 20rpx;" v-if="this.user.top==1">
				<view class="info_title" style="position: relative;">
				    消息提醒<text class="count" v-if="countshow3" >{{xiaoxi_num}}</text>
					<text class="info_more" @tap="message_look()" >查看更多</text>
				</view>
				<view class="border_bottom shenhe_list_container clear" v-for="(item,index) in xiaoxi" :key="index" @tap="gomessageinfo" :data-id="item.id">
					<view class="t_title left">
						{{item.title}}
					</view>
					<view class="right_time left">{{item.create_at}}</view>
				</view>
				<image src="../../static/img/nodata.png" class="no-data" v-if="ishas3"  mode="widthFix"></image>
				<!-- <view class="border_bottom shenhe_list_container">
					<view class="clear shenhe-text" >
						<text class="left">客户姓名 </text>
						<text class="right blue_text">刘月月</text>
					</view>	
					
					<view class="clear shenhe-text" >
						<text class="left">申请时间 </text>
						<text class="right">2020-12-12</text>
					</view>
				</view> -->
				
			</view>
			
		</view>
		<!-- 业务端完 ++++++++++++++++++-->
		<view class="menban" v-show="ispass">
			<view class="gray"></view>
				<view class="menban-content" style="top:calc(50% - 200rpx);left: 10%;right: 10%;border-radius:5px ;">
					<view class="line_title blue_title" style="position: relative;">
						友情提示
						<image src="../../static/img/close-icon.png" class="close-icon" @tap="isalertAction"></image>
					</view>
					<view  class="text" style="padding: 0px 60rpx;">
						为了保障您的资金安全，请修改密码！
					</view>
					<button class="big_button" style="margin: 30rpx auto;" @tap="gopass()">
						立即修改密码
					</button>
				</view>
		</view>
		<view style="height: 50px;"></view>
		<view class="footer clear">
			<view class="left" >
				<view class="footer_icon">
					<image :src="icon"></image>
				</view>
				<text class="footer_text" style="color: #1e99ff;">{{text}}</text>
			</view>
			<view class="left" @tap="gowode()">
				<view class="footer_icon">
					<image src="../../static/img/wode.png"></image>
				</view>
				<text class="footer_text">我的</text>
			</view>
		</view>
	</view>
</template>

<script>
	import httpPath from '@/static/js/path.js';
	import {getlogin} from '@/static/js/login.js';
	import {fmoney} from '@/static/js/login.js';
	import {timestampToDate1} from '@/static/js/login.js';
	export default {
		data() {
			return {
				isshenhe:false,
				countshow3:true,
				icon:"../../static/img/dai-active.png",
				text:"贷款",
				ishas1:false,//贷款审核列表是否有数据
				ishas2:false,//客户资料列表是否有数据
				ishas3:false,//客户资料列表是否有数据
				keyong:"0.00",//可用额度
				yiyong:"0.00",//已用额度
				lilv:"0.00",//利率额度
				total:"0.00",//总额度
				kehu:false,//是否是客户端
				yewu:false,//是否是业务
				isalert:false,//是否显示修改个人资料的提示框
				user:{},//用户登录信息
				ispass:false,//判断是否弹出修改密码的提示框
				memebr:[],//首页客户列表
				member_num:0,//客户列表数量
				capital:[],//贷款审核
				capital_num:0,//贷款审核列表
				countshow1:true,
				countshow2:true,
				info:{},
				xiaoxi:[],
				xiaoxi_num:0
			}
		},
		onBackPress() {  
		   if(this.showMask) {  
		     this.showMask = false;  
		     return true;  
		   }else{  
		      uni.showModal({  
		        title: '提示',  
		        content: '是否退出应用？',  
		        success: function(res) {  
		            if (res.confirm) {  
		                // 退出当前应用，改方法只在App中生效  
		                plus.runtime.quit();  
		            } else if (res.cancel) {  
		                console.log('用户点击取消');  
		            }  
		        }  
		      });  
		      return true;
		   }  
		},
		onShow(){
			this.isalert =false;
			this.ispass =false;
			this.isshenhe =false;
			this.user = getlogin();		
			if(!this.user.islogin){
				// uni.showModal({
				//    showCancel:false,
				//    content:"您还没有登录，请登录"
				// })
				uni.navigateTo({
					url:"../public/login"
				})
			}
			if(this.user.loginnum>0){
				this.ispass=false;
			}else{
				this.ispass=true;
			}
			if(this.user.type==1){
				this.getinfo();
				this.kehu=true;
				this.yewu = false;
				this.icon="../../static/img/dai-active.png";
				this.text="贷款"
			}else if(this.user.type==2){
				this.getdaikuan();
				this.yewu = true;
				this.kehu = false;
				this.text="待办";
				this.icon="../../static/img/daiban-active.png";
			
			}
			this.getinfo();
		},
		onLoad() {
			this.isalert =false;
			this.ispass =false;
			this.isshenhe = false;
            this.user = getlogin();		
			if(!this.user.islogin){
				// uni.showModal({
				//    showCancel:false,
				//    content:"您还没有登录，请登录"
				// })
				uni.navigateTo({
					url:"../public/login",
				})
			}
		   
			if(this.user.loginnum>0){
				this.ispass=false;
			}else{
				this.ispass=true;
				
			}
			if(this.user.type==1){
				this.getinfo();
				this.kehu=true;
				this.yewu = false;
				this.icon="../../static/img/dai-active.png";
				this.text="贷款"
			
			}else if(this.user.type==2){
				this.getdaikuan();
				this.yewu = true;
				this.kehu = false;
				this.text="待办";
				this.icon="../../static/img/daiban-active.png";
			}
			this.getinfo();
			// plus.key.addEventListener('backbutton',()=>{
			// 	uni.showModal({
			// 		content:"确定要退出应用吗？",
			// 		success: function (res) {
			// 			if (res.confirm) {
			// 				plus.runtime.quit();
			// 			}
			// 		}
			// 	})
		 //    })
			
			
		},
		methods: {
			message_look(){
				uni.navigateTo({
					url:"/pages/myself/messagelist",
				})
			},
			gowode(){
				uni.navigateTo({
					url:"../myself/index",
					animationType: 'none'
					// animationDuration: 0,
				})
			},
			daikuaninfo(){
				uni.navigateTo({
					url:"/pages/myself/shenhe"
				})
			},godaikuaninfo(e){
				uni.navigateTo({
					url:"/pages/myself/info?id="+e.currentTarget.dataset.id
				})
			},
			//去客户资料的详情
			gocsutem(e){
				uni.navigateTo({
					url:"../myself/ziliaoinfo?id="+e.currentTarget.dataset.id,
				})
			},//去客户资料的详情
			gomessageinfo(e){
				uni.navigateTo({
					url:"../myself/messageinfo?id="+e.currentTarget.dataset.id
				})
			},
			getdaikuan(){//获职员首页信息
				uni.request({
					url: httpPath.filePath+'api.php/index/user/wait_check/',
					method:'POST',
					header:{'content-type':'application/x-www-form-urlencoded'},
					data: {member_id:this.user.member_id,user_id:this.user.user_id},
					success: (res) => {
						// console.log(res)
						if(res.data.code=="200"){
							this.member_num=res.data.result.member_count;
							// this.member_num=res.data.result.memebr.length;
							if(this.member_num==0){
								this.ishas2=true;
								this.countshow2=false;
							}else{
								this.countshow2=true;
								this.ishas2=false;
							}
							this.memebr=res.data.result.memebr;
							this.capital=res.data.result.capital;
							this.capital_num=res.data.result.capital_count;
							if(this.capital_num==0){
								this.ishas1=true;
								this.countshow1=false;
							}
							if(this.capital_num!=0){
								
								this.countshow1=true;
								this.ishas1=false;
								for (let i=0;i<this.capital.length;i++) {
									this.capital[i].addtime=timestampToDate1(this.capital[i].addtime)
									console.log(this.capital[i].addtime)
								}
							}	
							this.xiaoxi_num=res.data.result.message_count;
							if(this.xiaoxi_num==0){
								this.ishas3=true;
								this.countshow3=false;
							}else{
								this.ishas3=false;
								this.countshow3=true;
								this.xiaoxi=res.data.result.message;
							}
						}	   
					}
				});
			},
			getinfo(){//获取客户端首页信息
				uni.request({
					url: httpPath.filePath+'/api.php/index/member/member_info/',
					method:'POST',
					header:{'content-type':'application/x-www-form-urlencoded'},
					data: {member_id:this.user.member_id},
					success: (res) => {
						if(res.data.code=="200"){
							this.info=res.data.result;
							this.yiyong=fmoney(res.data.result.used_capital,2)
							this.keyong=fmoney(res.data.result.use_capital,2)
							this.total=fmoney(res.data.result.capital,2)
							this.lilv=res.data.result.app_rate;
						}
						   
					}
				});
				
			},
           isalertAction(){
			   if(this.user.loginnum==0){
			      this.user.loginnum=1
			   }
			   uni.setStorage({
			       key: 'user',
			       data: this.user,
			       success: function () {
			           console.log('success');
			       }
			   });
			   
				this.ispass=false;
				this.isalert=false;
				this.isshenhe=false;
		   },goloan(){
			   if(this.info.tips==1){
				   this.isalert=true;
			   }else if(this.info.is_check!=1){//资料没有审核通过或者没有添加资料提示去添加资料
				   // this.isshenhe=true;
				    uni.showModal({
					    showCancel:false,
				   	    content:"您的资料正在审核，请耐心等待!"
				    })
			   }else{
				   uni.navigateTo({
				   	url:"../kehu/goloan"
				   })
			   }   
		   },gopass(){//跳转修改密码
			   if(this.user.loginnum==0){
				   this.user.loginnum=1
			   }
			   uni.setStorage({
				   key: 'user',
				   data: this.user,
				   success: function () {
					   console.log('success');
				   }
			   });
			   uni.navigateTo({
			   	url:"../public/setpass"
			   })
		   },gowanshan(){//跳转修改资料
			   
			   uni.navigateTo({
			   	url:"../public/edit_info"
			   })
		   },kehuinfo(){
			   uni.navigateTo({
			   	url:"/pages/myself/ziliao"
			   })
		   }
		}
	}
</script>

<style>
	@import "../../colorui/main.css";
   page{background: url(../../static/img/back.jpg)no-repeat;background-size:cover;background-position: top;}
   .no-data{width: 40%;display: block;margin: auto;height: 160rpx;}
   .info_title{padding-bottom: 8px;margin-bottom: 5px;}
   .info_more{margin-top: 10rpx;}
  .footer{height: 50px;position: fixed;bottom: 0px;left: 0px;width: 100%;box-shadow: -1px -1px 1px #dce0e7;display: flex;flex-direction: row;padding: 5px 0px;background: #FFFFFF;}
   .footer .left{width: 50%;text-align: center;}
   .footer_icon{width: 25px;height: 25px;margin: auto;}
   .footer_icon image{width: 100%;height: 100%;}
   .footer_text{font-size: 26rpx;color: #999999;}
   .t_title{font-size: 30rpx;color: #666;width: 50%;overflow: hidden;height: 30px;line-height: 30px;}
   .right_time{text-align: right;color: #999999;font-size: 28rpx;width: 50%;line-height: 30px;}
</style>
